const { execSync, exec } = require("child_process");
const path = require("path");
const { logger } = require("./logger");

const resourcePath = path.join(__dirname, "../build/res/");
const targetCdnUri = "qjwx_test/mini_test/";

logger.log("upload cdn start");
execSync("coscmd config -a AKIDLafy4v97WkjaM4t4PXklYEl9SiljE9cr -s GaHn3RPZXM5ZwX5sTtRnyyjJjNAnBSUG -b game-zj-cdn-1251697691 -r ap-shanghai -m 30 --do-not-use-ssl");
exec(`coscmd upload -r ${resourcePath} ${targetCdnUri}`, {
    maxBuffer: 1024 * 1024 * 1024,
}, (error, stdout, stderr) => {
    if (error) {
        logger.error(`upload cdn error`, error);
        return;
    }
    if (stderr) {
        logger.error(`upload cdn stderr`, stderr);
        return;
    }
    logger.log(`upload cdn success`);
});